//
//  RechargeViewController.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/10/5.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "RechargeViewController.h"
#import "WXApiManager.h"
#import <AlipaySDK/AlipaySDK.h>
#import "WXPayResultModel.h"
#import "AlipayDelegate.h"

@interface RechargeViewController () <WXApiManagerDelegate,AlipayRechargeDelegate,UIAlertViewDelegate>
@property (nonatomic, strong) UIScrollView *mainScroll;
@property (nonatomic, strong) NSDictionary *style;
@property (nonatomic, strong) NSDictionary *dict;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, assign) NSInteger money;
@property (nonatomic, assign) BOOL isWechat;
//查询支付的相关字段
//@property (copy, nonatomic) NSString *tradeno;
//@property (copy, nonatomic) NSString *payMoney;
//@property (copy, nonatomic) NSString *tmode;
//@property (copy, nonatomic) NSString *ttype;
@property(nonatomic,copy) NSString *keyID;
@end

@implementation RechargeViewController

- (void)setDict
{
    self.style = @{
                   @"black16":@[UIColorFromHex(0xA2A2A2),FontMediumWithSize(16)],
                   @"black12":@[UIColorFromHex(0xA2A2A2),FontMediumWithSize(12)],
                   @"select16":@[UIColorFromHex(0x444444),FontMediumWithSize(16)],
                   @"select12":@[UIColorFromHex(0x444444),FontMediumWithSize(12)],
                   };
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = TotalWhite;
    [self setNavi];
    [self setDict];
    [self getData];
    self.isWechat = YES; //默认微信支付
    //wxApiManager
    [WXApiManager sharedManager].delegate = self;
}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [TTKUtil getAppDelegate].alipayRechargeDelegate = nil;
}

- (void)getData
{
    self.dict = [NSDictionary dictionary];
    self.dataArray = [NSMutableArray array];
    [[HttpRequest currentHttpRequest]postPath:Recharge_API params:nil resultBlock:^(id Data, MsgModel *msgModel) {
        self.dict = [NSDictionary dictionaryWithDictionary:Data];
        NSArray *moneyArray = self.dict[@"rechargeActivities"];
        for (NSInteger i = 0; i < moneyArray.count; i++) {
            RechargeModel *model = [RechargeModel mj_objectWithKeyValues:moneyArray[i]];
            [self.dataArray addObject:model];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [self setMainView];
        });
    }];
}
- (void)setMainView
{
    if (self.mainScroll == nil) {
        
        self.mainScroll = [UIScrollView new];
        if (@available(iOS 11.0, *)) {
            self.mainScroll.frame = CGRectMake(0, TopBarHeight_xs, SCREENWIDTH, SCREENHEIGHT-TopBarHeight_xs);
        } else {
            // Fallback on earlier versions
            self.mainScroll.frame = CGRectMake(0, TopBarHeight, SCREENWIDTH, SCREENHEIGHT-TopBarHeight);
        }
        self.mainScroll.backgroundColor = ClearColor;
        self.mainScroll.contentSize = CGSizeMake(SCREENWIDTH, SCREENHEIGHT);
        [self.view addSubview:self.mainScroll];
        
        float bottom = 10;
        //获取接口banner
        NSDictionary *banner = self.dict[@"banner"];
        if (![TTKUtil isNil:banner])
        {
            UIImageView *headIV = [UIImageView new];
            headIV.frame = CGRectMake(0, bottom, SCREENWIDTH, 90);
            headIV.userInteractionEnabled = YES;
            [headIV sd_setImageWithURL:[NSURL URLWithString:banner[@"imageUrl"]] placeholderImage:[UIImage imageNamed:@"Placeholder400"]];
            [self.mainScroll addSubview:headIV];
            
//            UIImageView *blackIV = [UIImageView new];
//            blackIV.frame = CGRectMake(headIV.width-36, (headIV.height-16)/2, 16, 16);
//            blackIV.image = [UIImage imageNamed:@"blackBanner"];
//            blackIV.userInteractionEnabled = YES;
//            [headIV addSubview:blackIV];
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushHtml:)];
            [headIV addGestureRecognizer:tap];
            bottom = headIV.bottom;
        }
        
        UILabel *moneyLab = [UILabel new];
        moneyLab.frame = CGRectMake(15, bottom+10, 60, 14);
        moneyLab.textColor = UIColorFromHex(0x999999);
        moneyLab.font = FontWithSize(14);
        moneyLab.text = @"余额";
        [self.mainScroll addSubview:moneyLab];
        
        UILabel *numLab = [UILabel new];
        numLab.frame = CGRectMake(moneyLab.left, moneyLab.bottom+10, 150, 20);
        numLab.textColor = titleColor;
        numLab.tag = 88;
        numLab.font = FontSemiboldSize(20);
        numLab.text = [NSString stringWithFormat:@"%@元",self.dict[@"currentGoodsCapitalAmount"]];
        [self.mainScroll addSubview:numLab];
        
        UIView *lineV = [UIView new];
        lineV.frame = CGRectMake(0, numLab.bottom+15, SCREENWIDTH, 10);
        lineV.backgroundColor = UIColorFromHex(0xF7F7F7);
        [self.mainScroll addSubview:lineV];
        
        UIView *moneyView = [UIView new];
        moneyView.frame = CGRectMake(0, lineV.bottom, SCREENWIDTH, 206);
        moneyView.backgroundColor = TotalWhite;
        [self.mainScroll addSubview:moneyView];
        
        UILabel *rechargeLab = [UILabel new];
        rechargeLab.frame = CGRectMake(15, 20, 70, 14);
        rechargeLab.textColor = UIColorFromHex(0x999999);
        rechargeLab.font = FontMediumWithSize(14);
        rechargeLab.text = @"充值金额";
        [moneyView addSubview:rechargeLab];
        
        NSInteger quotient = self.dataArray.count/3;
        NSInteger remainder = self.dataArray.count%3;
        NSInteger index = remainder>0?quotient+1:quotient;
        //获取充值金额与tip
        CGFloat width = (SCREENWIDTH-15*4)/3;
        //    NSArray *titleArray = @[@"100元",@"200元",@"500元",@"1000元",@"2000元",@"5000元"];
        //    NSArray *desArray = @[@"赠送10元",@"赠送20元",@"赠送50元",@"赠送100元",@"赠送200元",@"赠送500元"];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < index; j++)
            {
                if (3*j+i < (int)self.dataArray.count)
                {
                    RechargeModel *model = self.dataArray[3*j+i];
                    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                    btn.frame = CGRectMake(15+(width+15)*i, rechargeLab.bottom+15+j*71, width, 56);
                    btn.layer.borderWidth = 1;
                    btn.layer.borderColor = goldColor.CGColor;
                    btn.tag = 100+3*j+i;
                    btn.titleLabel.textAlignment = NSTextAlignmentCenter;
                    btn.titleLabel.numberOfLines = 2;
                    [btn setBackgroundColor:TotalWhite];
                    
                    if (![TTKUtil isNil:model.tips]) {
                        [btn setAttributedTitle:[[NSString stringWithFormat:@"<black16>%@\n</black16><black12>%@</black12>",model.amount,model.tips]attributedStringWithStyleBook:self.style] forState:UIControlStateNormal];
                        [btn setAttributedTitle:[[NSString stringWithFormat:@"<select16>%@\n</select16><select12>%@</select12>",model.amount,model.tips]attributedStringWithStyleBook:self.style] forState:UIControlStateSelected];
                    }
                    else
                    {
                        [btn setAttributedTitle:[[NSString stringWithFormat:@"<black16>%@</black16>",model.amount]attributedStringWithStyleBook:self.style] forState:UIControlStateNormal];
                        [btn setAttributedTitle:[[NSString stringWithFormat:@"<select16>%@</select16>",model.amount]attributedStringWithStyleBook:self.style] forState:UIControlStateSelected];
                    }
                    [btn addTarget:self action:@selector(selectMoneyBtn:) forControlEvents:UIControlEventTouchUpInside];
                    if (i == 0 && j == 0) {
                        self.money = btn.tag;
                        btn.selected = YES;
                        btn.backgroundColor = goldColor;
                    }
                    if (index == 1) {
                        moneyView.height = 135;
                    }else if(index == 2)
                    {
                        moneyView.height = 206;
                    }else if (index == 3)
                    {
                        moneyView.height = 276;
                    }
                    
                    [moneyView addSubview:btn];
                }
            }
        }
        UIView *recharLine = [UIView new];
        recharLine.frame = CGRectMake(0, moneyView.bottom, SCREENWIDTH, 10);
        recharLine.backgroundColor = UIColorFromHex(0xF7F7F7);
        [self.mainScroll addSubview:recharLine];
        
        UILabel *chooseLab = [UILabel new];
        chooseLab.frame = CGRectMake(15, recharLine.bottom+11, 85, 14);
        chooseLab.textColor = UIColorFromHex(0x999999);
        chooseLab.font = FontMediumWithSize(14);
        chooseLab.text = @"选择充值方式";
        [self.mainScroll addSubview:chooseLab];
        
        //查看有几种充值方式
        NSArray *payMethod = self.dict[@"rechargePayMethods"];
        NSInteger method = payMethod.count;
        
        UIView *payView = [UIView new];
        payView.frame = CGRectMake(0, chooseLab.bottom, SCREENWIDTH, 122);
        [self.mainScroll addSubview:payView];
        
        if (method == 2) {
            NSArray *imageArray = @[@"wechat",@"ali"];
            NSArray *payTitle = @[@"微信支付",@"支付宝支付"];
            for (int m = 0; m < 2; m++) {
                UIImageView *leftIV = [UIImageView new];
                leftIV.frame = CGRectMake(15, 15+61*m, 30, 30);
                leftIV.image = [UIImage imageNamed:imageArray[m]];
                [payView addSubview:leftIV];
                
                UILabel *payLabel = [UILabel new];
                payLabel.frame = CGRectMake(leftIV.right+15, 22+61*m, 80, 16);
                payLabel.textColor = UIColorFromHex(0x999999);
                payLabel.font = FontMediumWithSize(16);
                payLabel.text = payTitle[m];
                [payView addSubview:payLabel];
                
                UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                rightBtn.frame = CGRectMake(SCREENWIDTH-31, payLabel.top, 16, 16);
                [rightBtn setBackgroundImage:[UIImage imageNamed:@"choose"] forState:UIControlStateNormal];
                [rightBtn setBackgroundImage:[UIImage imageNamed:@"chooseSelect"] forState:UIControlStateSelected];
                [rightBtn addTarget:self action:@selector(selectPayBtn:) forControlEvents:UIControlEventTouchUpInside];
                rightBtn.tag = 80+m;
                if (m == 0) {
                    rightBtn.selected = YES;
                }
                [payView addSubview:rightBtn];
                
                UIView *lineV = [UIView new];
                lineV.frame = CGRectMake(0, 60+61*m, SCREENWIDTH, 1);
                lineV.backgroundColor = UIColorFromHex(0xF1F1F1);
                [payView addSubview:lineV];
                
                UIButton *seleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                seleBtn.frame = CGRectMake(0, 61*m, SCREENWIDTH, 61);
                seleBtn.backgroundColor = ClearColor;
                seleBtn.tag = 90+m;
                [seleBtn addTarget:self action:@selector(selectPayBtn:) forControlEvents:UIControlEventTouchUpInside];
                [payView addSubview:seleBtn];
            }
        }
        else if (method == 1)
        {
            payView.height = 61;
            NSString *str = payMethod[0];
            if ([str isEqualToString:@"alipay"]) {
                self.isWechat = NO;
                [self setUpPayView:payView andImage:@"ali" andTitle:@"支付宝支付"];
            }
            else
            {
               self.isWechat = YES;
               [self setUpPayView:payView andImage:@"wechat" andTitle:@"微信支付"];
            }
        }
        
        UIButton *chargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        chargeBtn.frame = CGRectMake(40, payView.bottom+40, SCREENWIDTH-80, 50);
        chargeBtn.layer.cornerRadius = 20;
        chargeBtn.layer.masksToBounds = YES;
        [chargeBtn setTitleColor:titleColor forState:UIControlStateNormal];
        chargeBtn.backgroundColor = goldColor;
        chargeBtn.titleLabel.font = FontMediumWithSize(18);
        [chargeBtn setTitle:@"去充值" forState:UIControlStateNormal];
        [chargeBtn addTarget:self action:@selector(goToCharge:) forControlEvents:UIControlEventTouchUpInside];
        [self.mainScroll addSubview:chargeBtn];
        
        //设置可点击的textview
        ClickTextView *clickTV = [[ClickTextView alloc]initWithFrame:CGRectMake(40, chargeBtn.bottom+20, SCREENWIDTH-80, 50)];
        clickTV.backgroundColor = TotalWhite;
        clickTV.textColor = UIColorFromHex(0x999999);
        clickTV.font = FontMediumWithSize(14);
        NSString *content = @"点击去充值，即表示已阅读并同意《充值协议》\n异宝不会以任何形式要求您输入银行账户和密码";
        clickTV.text = content;
        NSRange range1 = [content rangeOfString:@"充值协议"];
        [clickTV setUnderLineTextViewWithRange:range1 withUnderLineColor:goldColor andWithCoverColor:nil withBlock:^(NSString *text) {
            WebViewController *web = [WebViewController new];
            web.urlString = @"http://serv.eb56.com/html/recharge-agreement.html";
            [self.navigationController pushViewController:web animated:YES];
        }];
        [self.mainScroll addSubview:clickTV];
        self.mainScroll.contentSize = CGSizeMake(SCREENWIDTH, clickTV.bottom+50);
    }
}

#pragma mark -- 判断一种支付方式的时候
- (void)setUpPayView:(UIView *)payView andImage:(NSString *)imageName andTitle:(NSString *)title
{
    UIImageView *leftIV = [UIImageView new];
    leftIV.frame = CGRectMake(15, 15, 30, 30);
    leftIV.image = [UIImage imageNamed:imageName];
    [payView addSubview:leftIV];
    
    UILabel *payLabel = [UILabel new];
    payLabel.frame = CGRectMake(leftIV.right+15, 22, 80, 16);
    payLabel.textColor = UIColorFromHex(0x999999);
    payLabel.font = FontMediumWithSize(16);
    payLabel.text = title;
    [payView addSubview:payLabel];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(SCREENWIDTH-31, payLabel.top, 16, 16);
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"chooseSelect"] forState:UIControlStateNormal];
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"chooseSelect"] forState:UIControlStateSelected];
    rightBtn.selected = YES;
    [payView addSubview:rightBtn];
    
    UIView *lineV = [UIView new];
    lineV.frame = CGRectMake(0, 60, SCREENWIDTH, 1);
    lineV.backgroundColor = UIColorFromHex(0xF1F1F1);
    [payView addSubview:lineV];
    
    UIButton *seleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    seleBtn.frame = CGRectMake(0, 0, SCREENWIDTH, 61);
    seleBtn.backgroundColor = ClearColor;
    [payView addSubview:seleBtn];
}

#pragma mark -- 选择充值金额
- (void)selectMoneyBtn:(UIButton *)btn
{
    for (NSInteger i = 0; i < self.dataArray.count; i++) {
        if (btn.tag == 100+i) {
            btn.selected = YES;
            btn.backgroundColor = goldColor;
            continue;
        }
        UIButton *chooseBtn = (UIButton *)[self.view viewWithTag:i+100];
        chooseBtn.selected = NO;
        chooseBtn.backgroundColor = TotalWhite;
    }
    self.money = btn.tag;
}

#pragma mark -- 选择充值方式
- (void)selectPayBtn:(UIButton *)btn
{
    NSLog(@"money = %li",(long)self.money);
    UIButton *ali = (UIButton *)[self.view viewWithTag:80];
    UIButton *wechat = (UIButton *)[self.view viewWithTag:81];
    if (btn.tag == 90) {
        self.isWechat = YES;
        ali.selected = YES;
        wechat.selected = NO;
    }else
    {
        self.isWechat = NO;
        ali.selected = NO;
        wechat.selected = YES;
    }
}

#pragma  mark -- 充值按钮点击
- (void)goToCharge:(UIButton *)btn
{
    RechargeModel *model = self.dataArray[self.money-100];
    NSString *m = model.amount;
    NSLog(@"money = %@ \n ali = %d",m,self.isWechat);
    
    NSString *money = [m stringByReplacingOccurrencesOfString:@"元" withString:@""];
    if (self.isWechat==YES) {
        [self prepayWithWechat:money];
    }else
    {
        [self prepayWithAliWith:money];
    }
    
}

#pragma mark -- 支付宝支付
- (void)prepayWithAliWith:(NSString *)amount
{
    //设置回调代理
    [TTKUtil getAppDelegate].alipayRechargeDelegate = self;
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:amount forKey:@"amount"];
    [dict setValue:[NSNumber numberWithInteger:1] forKey:@"capitalType"]; //充值类型。1: 货款， 100:保证金
    [HttpRequest formPostPath:Alipay_Pay_API params:dict resultBlock:^(id Data, MsgModel *msgModel) {
        NSString *orderString = [NSString stringWithFormat:@"%@",Data[@"result"]];
        [[AlipaySDK defaultService]payOrder:orderString fromScheme:@"YiBao" callback:^(NSDictionary *resultDic) {
            //没有安装支付宝，网页支付宝回调
            [self handleAlipayWith:resultDic];
        }];
    }];
}

- (void)handleAlipayWith:(NSDictionary *)resultDict
{
    NSInteger resultStatus = [resultDict[@"resultStatus"]integerValue];
    if (resultStatus == 6001) {
        [self ShowHUDWithMessage:resultDict[@"memo"]];
        return;
    }
    NSError *parseError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:resultDict options:NSJSONWritingPrettyPrinted error:&parseError];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:jsonString forKey:@"clientPayResultJsonString"];
    [HttpRequest formPostPath:Alipay_pay_Success_API params:dict resultBlock:^(id Data, MsgModel *msgModel) {
        
        NSString *money = [NSString stringWithFormat:@"%@",Data[@"result"]];
        NSInteger resultStatus = [resultDict[@"resultStatus"]integerValue];
        //支付成功
            if (resultStatus == 9000)
        {
            [self ShowHUDWithMessage:@"充值成功"];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                //刷新余额
                [self refreshMoneyLab:money];
                [self.navigationController popToRootViewControllerAnimated:YES];
            });
        }
    }];
}

#pragma mark -- 支付宝回调
- (void)getAlipayRechargeResult:(NSDictionary *)dict
{
    [self handleAlipayWith:dict];
}

#pragma mark -- 微信支付
- (void)prepayWithWechat:(NSString *)amount
{
    double money = [amount doubleValue];
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:[NSNumber numberWithDouble:money] forKey:@"amount"];
    [dict setValue:[NSNumber numberWithInteger:1] forKey:@"capitalType"]; //充值类型。1: 货款， 100:保证金
    [HttpRequest formPostPath:Wechat_Pay_API params:dict resultBlock:^(id Data, MsgModel *msgModel) {
        NSDictionary *dict = Data[@"result"];
        self.keyID = dict[@"outTradeNo"];
        WXPayResultModel *model = [WXPayResultModel mj_objectWithKeyValues:dict];
        //判断是否安装微信
        if ([WXApi isWXAppInstalled]) {
            //发起微信支付
            PayReq *request = [[PayReq alloc]init];
            request.openID = model.appid;
            request.partnerId = model.partnerid; //商家id/商户号
            request.prepayId = model.prepayid;//预支付订单
            request.nonceStr = model.noncestr;//随机字符串
            request.sign = model.sign;//签名
            request.timeStamp = model.timestamp;//时间戳，防止重发
            request.package = model.package;//扩展字段
            [WXApi sendReq:request];
        }else
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"没有安装微信app" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            }];
            [alert addAction:action2];
            [self presentViewController:alert animated:YES completion:nil];
        }
        
    }];
}

#pragma mark -- 微信回调
- (void)managerDidReceviePayResult:(PayResp *)resp
{
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:[NSNumber numberWithInteger:[self.keyID integerValue]] forKey:@"rechargeOrderId"];
    [HttpRequest formPostPath:wechat_Pay_Success_API params:dict resultBlock:^(id Data, MsgModel *msgModel) {
        NSString *money = [NSString stringWithFormat:@"%@",Data[@"result"]];
        switch (resp.errCode) {
            case WXSuccess:
            {
                [self ShowHUDWithMessage:@"充值成功"];
                //刷新余额
                [self refreshMoneyLab:money];
            }
                break;
            case WXErrCodeUserCancel:
            {
                [self ShowHUDWithMessage:@"用户取消充值"];
            }
                break;
            default:
                break;
        }
    }];
}

#pragma marj -- 刷新货款余额
- (void)refreshMoneyLab:(NSString *)money
{
    UILabel *label = (UILabel *)[self.view viewWithTag:88];
//    [self getData];
    label.text = [NSString stringWithFormat:@"%@元",money];
}

- (void)setNavi
{
    self.bgNavView.hidden = YES;
    UIView *navi = [UIView new];
    if (@available(iOS 11.0, *)) {
        navi.frame = CGRectMake(0, 0, SCREENWIDTH, TopBarHeight_xs);
    } else {
        // Fallback on earlier versions
        navi.frame = CGRectMake(0, 0, SCREENWIDTH, TopBarHeight);
    }
    navi.backgroundColor = TotalWhite;
    [self.view addSubview:navi];
    
    UIImageView *leftIV = [UIImageView new];
    leftIV.frame = CGRectMake(15, navi.height-15-18, 18, 14);
    leftIV.image = [UIImage imageNamed:@"back"];
    [navi addSubview:leftIV];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(8, navi.height-40, 32, 28);
    leftBtn.backgroundColor = ClearColor;
    [leftBtn addTarget:self action:@selector(leftBtnBackClick:) forControlEvents:UIControlEventTouchUpInside];
    [navi addSubview:leftBtn];
    
    UILabel *titleLab = [UILabel new];
    CGFloat left = 30+18;
    titleLab.frame = CGRectMake(left, navi.height-13-18, SCREENWIDTH-96, 18);
    titleLab.textColor = titleColor;
    titleLab.font = FontSemiboldSize(18);
    titleLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:-0.9 and:@"充值"];
    titleLab.textAlignment = NSTextAlignmentCenter;
    [navi addSubview:titleLab];
    /*
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(SCREENWIDTH-55, navi.height-45, 40, 35);
    [rightBtn setAttributedTitle:[TTKUtil getAtttributeStringWithLineSpace:0 kern:-0.7 and:@"明细"] forState:UIControlStateNormal];
    rightBtn.backgroundColor = [UIColor clearColor];
    rightBtn.titleLabel.font = [UIFont fontWithName:@".AppleSystemUIFont" size:14];
    [rightBtn setTitleColor:titleColor forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(desBtn:) forControlEvents:UIControlEventTouchUpInside];
    [navi addSubview:rightBtn];
    */
}

- (void)desBtn:(UIButton *)btn
{
    NSLog(@"des");
}

- (void)pushHtml:(UITapGestureRecognizer *)tap
{
    NSString *url = self.dict[@"banner"][@"clickUrl"];
    WebViewController *webVC = [[WebViewController alloc]init];
    webVC.urlString = url;
    [self.navigationController pushViewController:webVC animated:YES];
}

- (void)leftBtnBackClick:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
